﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ActivitiesControl.Domain.Model;
using ActivitiesControl.Domain.Utils;

namespace ActivitiesControl.Domain.Services.Impls
{
	[ExceptionMessageHandler]
	internal class ProjectCustomerServices
		: BaseServices, IProjectServices, ICustomerServices
	{
		public override event MessageHandler MessageRaised = delegate(object sender, MessageEventArgs e) { };

		internal override void RaiseMessage(object sender, MessageEventArgs e)
		{
			MessageRaised(sender, e);
		}

		public IEnumerable<Project> GetProjectsByCustomerId(int customerId)
		{
			IEnumerable<Project> result = ProjectRepository.GetProjectsByCustomerId(customerId);
			MessageRaised(this, new MessageEventArgs { Message = new Message("Projetos", "Projetos retornados com sucesso.", MessageType.Ok) });
			return result;
		}

		public Project GetProjectById(int id)
		{
			Project result = ProjectRepository.GetById(id);
			MessageRaised(this, new MessageEventArgs { Message = new Message("Projeto", "Projeto retornado com sucesso.", MessageType.Ok) });
			return result;
		}

		public IEnumerable<Project> GetProjectsForFilter(int customerId)
        {
			IEnumerable<Project> projects = ProjectRepository.GetProjectsByCustomerId(customerId);

			IList<Project> list = new List<Project>();

			list.Add(new Project { Name = "Todos", Id = -999 });

			foreach (var project in projects)
				list.Add(project);

			return list;
        }

		public IEnumerable<Customer> GetCustomersForFilter()
		{
			return CustomerRepository.GetAll();
		}
	}
}
